package cn.edu.cqyz.wisdom.util;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.*;
import com.aliyun.teautil.models.RuntimeOptions;
import com.google.gson.Gson;

/**
 * @Description TODO
 * @Author CDHong
 * @Date Created in 2024/12/18 11:13
 * @Version 1.0
 */
import com.aliyun.tea.*;

public class SampleUtil {

    private static final String ALIBABA_CLOUD_ACCESS_KEY_ID = "LTAI5tPvfDtGdTPXCujgZ7qU";
    private static final String ALIBABA_CLOUD_ACCESS_KEY_SECRET = "605fdUXWIg4w1f7vBZQ5qT61YCdZJ4";

    /**
     * <b>description</b> :
     * <p>使用AK&amp;SK初始化账号Client</p>
     * @return Client
     *
     * @throws Exception
     */
    public static SendSmsResponse SendSms(String tel,String tempCode,Integer randNum) throws Exception {
        // 工程代码泄露可能会导致 AccessKey 泄露，并威胁账号下所有资源的安全性。以下代码示例仅供参考。
        // 建议使用更安全的 STS 方式，更多鉴权访问方式请参见：https://help.aliyun.com/document_detail/378657.html。
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
                .setAccessKeyId(ALIBABA_CLOUD_ACCESS_KEY_ID)
                // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
                .setAccessKeySecret(ALIBABA_CLOUD_ACCESS_KEY_SECRET);
        // Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
        config.endpoint = "dysmsapi.aliyuncs.com";
        Client client = new com.aliyun.dysmsapi20170525.Client(config);
        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
                .setPhoneNumbers(tel)
                .setSignName("智慧AI")
                .setTemplateCode(tempCode)
                .setTemplateParam("{\"code\":\""+randNum+"\"}");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        /**
         * Response {
         *   "Message": "OK",
         *   "RequestId": "0D7B339B-E40E-513A-81AA-F74AB744CBFF",
         *   "Code": "OK",
         *   "BizId": "205220334920141379^0"
         * }
         */
        return client.sendSmsWithOptions(sendSmsRequest, runtime);
    }

}
